package com.fzhucc.modules.lesson.rest;

import com.fzhucc.annotation.Log;
import com.fzhucc.modules.lesson.domain.LessonIntegral;
import com.fzhucc.modules.lesson.service.LessonIntegralService;
import com.fzhucc.modules.system.service.UserService;
import com.fzhucc.modules.system.service.dto.UserQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
* @author yyg
* @date 2022-12-07
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "课程:积分管理")
@RequestMapping("/api/lessonIntegral")
public class LessonIntegralController {

    private final LessonIntegralService lessonIntegralService;

    private final UserService userService;

    /*@Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('lessonIntegral:list')")
    public void exportLessonIntegral(HttpServletResponse response, LessonIntegralQueryCriteria criteria) throws IOException {
        lessonIntegralService.download(lessonIntegralService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询integral")
    @ApiOperation("查询integral")
    @PreAuthorize("@el.check('lessonIntegral:list')")
    public ResponseEntity<Object> queryLessonIntegral(LessonIntegralQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(lessonIntegralService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增integral")
    @ApiOperation("新增integral")
    @PreAuthorize("@el.check('lessonIntegral:add')")
    public ResponseEntity<Object> createLessonIntegral(@Validated @RequestBody LessonIntegral resources){
        return new ResponseEntity<>(lessonIntegralService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改integral")
    @ApiOperation("修改integral")
    @PreAuthorize("@el.check('lessonIntegral:edit')")
    public ResponseEntity<Object> updateLessonIntegral(@Validated @RequestBody LessonIntegral resources){
        lessonIntegralService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除integral")
    @ApiOperation("删除integral")
    @PreAuthorize("@el.check('lessonIntegral:del')")
    public ResponseEntity<Object> deleteLessonIntegral(@RequestBody Integer[] ids) {
        lessonIntegralService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }*/

    @GetMapping(value = "/queryLessonIntegralByLoginUser")
    @Log("查询当前用户登录积分")
    @ApiOperation("查询当前用户登录积分")
    public ResponseEntity<Object> queryLessonIntegralByLoginUser(){
        return new ResponseEntity<>(lessonIntegralService.queryLessonIntegralByLoginUser(),HttpStatus.OK);
    }

    @GetMapping(value = "/queryUser")
    @Log("积分管理查询用户列表")
    @ApiOperation("积分管理查询用户列表")
    public ResponseEntity<Object> queryUser(UserQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(userService.queryAllWithIntegral(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping(value = "/addUserLessonIntegral")
    @Log("用户赋予积分")
    @ApiOperation("用户赋予积分")
    public ResponseEntity<Object> addUserLessonIntegral(@RequestBody LessonIntegral resources){
        lessonIntegralService.addUserLessonIntegral(resources);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}